library(dplyr)
library(tidyr)
library(ggplot2)

#set working directory to wherever raw data is

sf2 <- read.table("f0_measurements sf2.txt", sep = "\t", header = TRUE)
sf2 <- sf2[, c(1,3,7:16)]
sf2$accent <- "short falling"
sf2$size <- "disyllabic"

sf3 <- read.table("f0_measurements sf3.txt", sep = "\t", header = TRUE)
sf3 <- sf3[, c(1,3,7:16)]
sf3$accent <- "short falling"
sf3$size <- "trisyllabic"

lf2 <- read.table("f0_measurements lf2.txt", sep = "\t", header = TRUE)
lf2 <- lf2[, c(1,3,7:16)]
lf2$accent <- "long falling"
lf2$size <- "disyllabic"

lf3 <- read.table("f0_measurements lf3.txt", sep = "\t", header = TRUE)
lf3 <- lf3[, c(1,3,7:16)]
lf3$accent <- "long falling"
lf3$size <- "trisyllabic"

lr2 <- read.table("f0_measurements lr2.txt", sep = "\t", header = TRUE)
lr2 <- lr2[, c(1,3,7:16)]
lr2$accent <- "long rising"
lr2$size <- "disyllabic"

lr3 <- read.table("f0_measurements lr3.txt", sep = "\t", header = TRUE)
lr3 <- lr3[, c(1,3,7:16)]
lr3$accent <- "long rising"
lr3$size <- "trisyllabic"

# create master file
pitch_data <- rbind(sf2, sf3, lf2, lf3, lr2, lr3)

# reorganize master file
pitch_data <- pitch_data %>%
  pivot_longer(cols = c(f0_1,f0_2,f0_3,f0_4,f0_5,f0_6,f0_7,f0_8,f0_9,f0_10),
               values_to = "f0",
               names_to = "time point") %>%
  mutate(f0 = as.numeric(f0))

# change working directory to analysis
# save master file
write.csv(pitch_data, "pitch data.csv")
